package com.demo.webapp.views.freemarker.directive.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 指令模型
 * @author ryuu.kk
 *
 */
public class DirectiveModel implements java.io.Serializable {

	/**
	 * 版本序列化ID
	 */
	private static final long serialVersionUID = -2648171695170059080L;

	/**
	 * 指令名
	 */
	private String name;
	
	/**
	 * 指令类
	 */
	private String tagclass;
	
	/**
	 * 指令描述
	 */
	private String description;
	
	/**
	 * 指令参数Map
	 */
	private Map<String, Attribute> attributeMap;
	
	/**
	 * 指令参数List
	 */
	private List<Attribute> attributeList;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTagclass() {
		return tagclass;
	}

	public void setTagclass(String tagclass) {
		this.tagclass = tagclass;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Map<String, Attribute> getAttributeMap() {
		return attributeMap;
	}
	
	public void addAttribute(Attribute attribute) {
		
		if (attributeList == null) {
			attributeList = new ArrayList<Attribute>();
		}
		attributeList.add(attribute);
	}
	
	public List<Attribute> getAttributeList() {
		return attributeList;
	}

	public void setAttributeList(List<Attribute> attributeList) {
		this.attributeList = attributeList;
	}

	//初始化
	public void init() {
		if (attributeList != null) {
			if (attributeMap == null) {
				attributeMap = new HashMap<String, Attribute>();
			}
			for (Attribute attribute : attributeList) {
				attributeMap.put(attribute.getName(), attribute);
			}
		}
	}
}
